import { DataProvider } from "../../../../fl/data/DataProvider";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { GComboBox } from "../../../../com/mui/controls/GComboBox";
import { ComboBoxItemCellRender } from "./ComboBoxItemCellRender";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { MsgManager } from "../../manager/MsgManager";
import { LockInfoData } from "./LockInfoData";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
type int = number;
//class SetProtectInfoSprite
    
    export  class SetProtectInfoSprite /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._quesDp = new DataProvider();
            this._quesDp.addItem({"id": 1, "label": Language.getString(90215)});
            this._quesDp.addItem({"id": 2, "label": Language.getString(90216)});
            this._quesDp.addItem({"id": 3, "label": Language.getString(90217)});
            this._quesDp.addItem({"id": 4, "label": Language.getString(90218)});
            this._quesDp.addItem({"id": 5, "label": Language.getString(90219)});
            this._quesDp.addItem({"id": 6, "label": Language.getString(90220)});
            this._quesDp.addItem({"id": 7, "label": Language.getString(90221)});
            this._quesDp.addItem({"id": 8, "label": Language.getString(90222)});
            var loc1=ObjCreate.createBg(10, 255, 280, 2, this, ImagesConst.SplitLine);
            var loc2=ObjCreate.createTextField("", 10, 10, 50, 20, this);
            loc2.htmlText = "<font size=\'12\' color=\'#f1ffb1\'>" + Language.getString(35542) + "</font>";
            loc2.filters = [];
            var loc3=ObjCreate.createTextField("", 10, 130, 50, 20, this);
            loc3.htmlText = "<font size=\'12\' color=\'#f1ffb1\'>" + Language.getString(35543) + "</font>";
            loc3.filters = [];
            this._ques1Combo = this.createComboBox(70, 30, 200, 25, this._quesDp);
            this._ques1Combo.addEventListener(flash.events.Event.CHANGE, this.onQues1ComboChangeHandler);
            this._ques2ComBo = this.createComboBox(70, 150, 200, 25, this._quesDp);
            this._ques2ComBo.addEventListener(flash.events.Event.CHANGE, this.onQues2ComboChangeHandler);
            this._ques2ComBo.selectedIndex = this._selectedIndex2;
            var loc4;
            (loc4 = ObjCreate.createTextField("", 10, 70, 200, 20, this)).htmlText = Language.getString(35544);
            loc4.filters = [];
            var loc5;
            (loc5 = ObjCreate.createTextField("", 10, 190, 200, 20, this)).htmlText = Language.getString(35545);
            loc5.filters = [];
            this._answer1Txt = ObjCreate.createGTextInput(70, 90, 200, 25, this);
            this._answer1Txt.textField.maxChars = 40;
            this._answer2Txt = ObjCreate.createGTextInput(70, 210, 200, 25, this);
            this._answer2Txt.textField.maxChars = 40;
            var loc6=Language.getString(35546);
            var loc7;
            (loc7 = ObjCreate.createTextField("", 10, 270, 280, 50, this)).defaultTextFormat = new GTextFormat("", 12, 11661311, null, null, null, null, null, null, null, null, null, 5);
            loc7.filters = [];
            loc7.wordWrap = true;
            loc7.multiline = true;
            loc7.htmlText = "<font size=\'12\' color=\'#b1efff\'>" + loc6 + "</font>";
            return;
        }

        /* internal  */createComboBox(arg1: int, arg2: int, arg3: int, arg4: int, arg5: DataProvider): GComboBox
        {
            var loc1;
            (loc1 = new GComboBox()).selectedIndex = 0;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.move(arg1, arg2);
            loc1.styleName = "GComboboxStyle";
            loc1.drawNow();
            loc1.dropdown.setStyle("cellRenderer", ComboBoxItemCellRender);
            loc1.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            loc1.textField.setStyle("textFormat", new GTextFormat("", 12, 11661308, false, false, false, "", "", flash.text.TextFormatAlign.LEFT));
            loc1.dataProvider = arg5;
            addChild(loc1);
            return loc1;
        }

        /* internal  */onQues1ComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._ques1Combo.selectedIndex != this._selectedIndex2) 
            {
                this._selectedIndex1 = this._ques1Combo.selectedIndex;
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(35547));
                this._ques1Combo.selectedIndex = this._selectedIndex1;
            }
            return;
        }

        /* internal  */onQues2ComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._ques2ComBo.selectedIndex != this._selectedIndex1) 
            {
                this._selectedIndex2 = this._ques2ComBo.selectedIndex;
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(35547));
                this._ques2ComBo.selectedIndex = this._selectedIndex2;
            }
            return;
        }

        public setProtectInfo(): Boolean
        {
            var loc1=false;
            var loc2=this._ques1Combo.selectedItem.label;
            var loc3=this._ques2ComBo.selectedItem.label;
            var loc4=this._answer1Txt.text;
            var loc5=this._answer2Txt.text;
            if (loc4 != "") 
            {
                if (loc5 != "") 
                {
                    if (this.isChinese(loc4) && loc4.length < 2 || this.isChinese(loc5) && loc5.length < 2) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(35550));
                    }
                    else if (!this.isChinese(loc4) && loc4.length < 4 || !this.isChinese(loc5) && loc5.length < 4) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(35551));
                    }
                    else if (loc4.length > 40 || loc5.length > 40) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(35552));
                    }
                    else if (loc2 != loc3) 
                    {
                        if (loc4 != loc5) 
                        {
                            LockInfoData.questionOne = loc2;
                            LockInfoData.questionTwo = loc3;
                            LockInfoData.answerOne = loc4;
                            LockInfoData.answerTwo = loc5;
                            loc1 = true;
                        }
                        else 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(35553));
                        }
                    }
                    else 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(35547));
                    }
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(35549));
                }
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(35548));
            }
            return loc1;
        }

        /* internal  */isChinese(arg1: string): Boolean
        {
            var loc1=0;
            while (loc1 < arg1.length) 
            {
                if (arg1.charCodeAt(loc1) > 255) 
                {
                    return true;
                }
                ++loc1;
            }
            return false;
        }

        public resetSprite(): void
        {
            this._answer1Txt.text = "";
            this._answer2Txt.text = "";
            return;
        }

        /* internal */ /* var */_quesDp: DataProvider;

        /* internal */ /* var */_ques1Combo: GComboBox;

        /* internal */ /* var */_ques2ComBo: GComboBox;

        /* internal */ /* var */_answer1Txt: GTextInput;

        /* internal */ /* var */_answer2Txt: GTextInput;

        /* internal */ /* var */_selectedIndex1: int=0;

        /* internal */ /* var */_selectedIndex2: int=1;
    }
